package com.dw.article.controller;

import com.dw.article.service.ReplyUserService;
import com.dw.common.entitys.BaseResponse;
import com.dw.common.utils.ResultUtils;
import com.dw.model.article.dtos.comment.LikeCommentDTO;
import com.dw.model.article.dtos.reply.LikeReplyDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 回复用户关系表(ReplyUser)表控制层
 *
 * @author makejava
 * @since 2024-11-08 08:50:00
 */
@Slf4j
@RestController
@RequestMapping("/article/reply/user")
public class ReplyUserController {

    @Resource
    private ReplyUserService replyUserService;

    /**
     * 点赞
     */
    @PostMapping("/like")
    public BaseResponse<Boolean> like(@RequestBody LikeReplyDTO likeReplyDTO) {
        log.info("点赞参数:{}", likeReplyDTO);
        replyUserService.like(likeReplyDTO);
        return ResultUtils.success(true);
    }

    /**
     * 获取回复点赞数量
     */
    @GetMapping("/getCount")
    public BaseResponse<Integer> getReplyLikeCount(Long replyId) {
        log.info("获取评论点赞数量参数:{}", replyId);
        return ResultUtils.success(replyUserService.getReplyLikeCount(replyId));
    }

    /**
     * 查询当前用户是否点赞
     */
    @GetMapping("/isLike")
    public BaseResponse<Integer> isLike(Long replyId) {
        log.info("查询当前用户是否点赞参数:{}", replyId);
        Integer liked = replyUserService.isLike(replyId);
        return ResultUtils.success(liked);
    }
}